﻿Imports CrystalDecisions.CrystalReports.Engine
''' <summary>
''' 銷售統計分析報表·
''' </summary> songrenhua 2009-06
''' <remarks></remarks>
Public Class Frm_SALRetailGrowth

    Implements IDServer.IDServer.IDServer
    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp
    Private WithEvents MainForm As Frm_MainForm
    Private TabPage1date As String = Nothing
    Private TabPage2date As String = Nothing
    Private TabPage3date As String = Nothing
    Private SQL As String
    Private DS As DataSet
    Private startDate As String = ""
    Private endDate As String = ""
    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property

#Region ""
    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd

    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel

    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete

    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit

    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave

    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function
#End Region

    Private Function ReturnCaption(ByVal index As Integer) As Hashtable
        Try
            Dim Hash As New Hashtable
            Select Case index
                Case 1
                    Hash.Add("RIQI", "日期")
                    Hash.Add("DANGTIAN", "總金額")
                    Hash.Add("ZENGZHANGLV", "增長率")
                    Hash.Add("QIANYITIAN", "前一天總金額")

                Case 2
                    Hash.Add("MONTH", "月")
                    Hash.Add("DANGYUE", "當月總金額")
                    Hash.Add("ZENGZHANGLV", "增長率")
                    Hash.Add("QIANYIYUE", "前一月總金額")

                Case 3
                    Hash.Add("YEAR1", "年")
                    Hash.Add("DANGNIAN", "當年總金額")
                    Hash.Add("ZENGZHANGLV", "增長率")
                    Hash.Add("QIANYINIAN", "前一年總個金額")
                Case 4
                    Hash.Add("FSALEDATE", "銷售日期")
                    Hash.Add("TAMOUNT", "總金額")
                    Hash.Add("AMOUNT", "銷售單數")
                    Hash.Add("AVG", "平均銷售單價格")
                Case 5
                    Hash.Add("FSALEDATE", "銷售日期")
                    Hash.Add("TAMOUNT", "總金額")
                    Hash.Add("AMOUNT", "銷售數")
                    Hash.Add("AVG", "平均銷售單價格")

            End Select
            Return Hash
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Function

    Private Sub BtnJS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnJS.Click
        Try
            startDate = Me.DateTimePicker1.Text
            endDate = Me.DateTimePicker2.Text
            If Me.RBtnD.Checked = True Then
                SelectWithDate(True)
            End If
            If Me.RBtnM.Checked = True Then
                SelectWithMonth(True)
            End If
            If Me.RBtnY.Checked = True Then
                SelectWithYear(True)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub BtnTJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTJ.Click
        Try
            startDate = Me.DateTimePicker3.Text
            endDate = Me.DateTimePicker4.Text
            AVGSalPrice(True)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub AVGSalPrice(ByVal B As Boolean)
        Try
            SQL = "   SELECT A.FSALEDATE, SUM(FSUMMONEY) AS TAMOUNT,C.AMOUNT,AVG= SUM(FSUMMONEY)/C.AMOUNT " & vbCrLf
            'SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B  " & vbCrLf  '只查詢一天的數據的時候速度會很慢，查詢多天的卻沒問題，不知道什麽原因，所以改成了inner join
            SQL += " FROM SAL_SALEORDEA A Inner JOIN SAL_SALEORDEB B  " & vbCrLf
            SQL += " ON A.FSALEORDENO = B.FSALEORDENO LEFT JOIN  " & vbCrLf
            SQL += " (SELECT  FSALEDATE,COUNT(FSALEORDENO)AS AMOUNT FROM SAL_SALEORDEA " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker3.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker4.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += " GROUP BY FSALEDATE )C  ON A.FSALEDATE = C.FSALEDATE " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND  A.FSALEDATE  BETWEEN '" & Me.DateTimePicker3.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker4.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            If B = True Then
                SQL += " AND 1 = 1 "
            Else
                SQL += " AND 1<>1"
            End If
            SQL += "   GROUP BY A.FSALEDATE,C.AMOUNT order by a.FSALEDATE " & vbCrLf
            DS = Exec(SQL, E_ExecType.DataSet)
            Me.DataGridView2.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView2, Me.ReturnCaption(4))
            Me.TabPage2date = String.Concat("統計時間由：  ", startDate, "  到  ", endDate)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
    Private Sub SelectWithYear(ByVal B As Boolean)
        Try
            SQL = "   SELECT A.YEAR1,A.AMOUNT AS DANGNIAN, " & vbCrLf
            SQL += " ZENGZHANGLV=  CAST(((A.AMOUNT-ISNULL(B.AMOUNT,A.AMOUNT))/( CASE WHEN ISNULL(B.AMOUNT,A.AMOUNT)=0 THEN 1 ELSE ISNULL(B.AMOUNT,A.AMOUNT) END ))*100 AS VARCHAR(100))+'%',B.AMOUNT AS QIANYINIAN  " & vbCrLf
            SQL += " FROM " & vbCrLf
            SQL += "  (SELECT  YEAR(A.FSALEDATE) AS YEAR1, YEAR(A.FSALEDATE)*10000+'0101' as YEAR ,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT  " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += "  GROUP BY  YEAR(A.FSALEDATE)) A LEFT JOIN " & vbCrLf
            SQL += "   (SELECT   YEAR(A.FSALEDATE) AS YEAR1, YEAR(A.FSALEDATE)*10000+'0101' as YEAR ,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT  " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += "  GROUP BY  YEAR(A.FSALEDATE)) B " & vbCrLf
            SQL += "   ON DATEADD(YEAR,1,CONVERT(DATETIME,CONVERT(NVARCHAR(100),B.YEAR)))=CONVERT(DATETIME,CONVERT(NVARCHAR(100),a.YEAR))  "
            If B = True Then
                SQL += " where 1 =1 "
            Else
                SQL += " where 1<>1"
            End If
            SQL += "   ORDER BY A.YEAR1  " & vbCrLf
            DS = Exec(SQL, E_ExecType.DataSet)
            Me.DataGridView1.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView1, Me.ReturnCaption(3))
            Me.TabPage1date = String.Concat(" 按年統計  時間由：  ", startDate, "  到  ", endDate)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub SelectWithMonth(ByVal B As Boolean)
        Try
            SQL = "  SELECT left(a.YM,6) as MONTH, A.AMOUNT AS DANGYUE," & vbCrLf
            SQL += " ZENGZHANGLV=  CAST(((A.AMOUNT-ISNULL(B.AMOUNT,A.AMOUNT))/( CASE WHEN ISNULL(B.AMOUNT,A.AMOUNT)=0 THEN 1 ELSE ISNULL(B.AMOUNT,A.AMOUNT) END ))*100 AS VARCHAR(100))+'%',B.AMOUNT AS QIANYIYUE " & vbCrLf
            SQL += " FROM " & vbCrLf
            SQL += "  (SELECT  (DATEPART(YEAR,A.FSALEDATE)*100+DATEPART(MONTH,A.FSALEDATE))*100+'01' AS YM,YEAR(A.FSALEDATE) AS YEAR,  MONTH(A.FSALEDATE) AS MONTH ,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT  " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += "  GROUP BY DATEPART(YEAR,A.FSALEDATE)*100+DATEPART(MONTH,A.FSALEDATE), YEAR(A.FSALEDATE),MONTH(A.FSALEDATE)) A LEFT JOIN " & vbCrLf
            SQL += "  (SELECT   (DATEPART(YEAR,A.FSALEDATE)*100+DATEPART(MONTH,A.FSALEDATE))*100+'01' AS YM, YEAR(A.FSALEDATE) AS YEAR, MONTH(A.FSALEDATE) AS MONTH ,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT  " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += "  GROUP BY DATEPART(YEAR,A.FSALEDATE)*100+DATEPART(MONTH,A.FSALEDATE), YEAR(A.FSALEDATE),MONTH(A.FSALEDATE))B " & vbCrLf
            SQL += "  ON DATEADD(MONTH,1,CONVERT(DATETIME,CONVERT(NVARCHAR(10),B.YM)))=CONVERT(DATETIME,CONVERT(NVARCHAR(10),A.YM)) "
            If B = True Then
                SQL += " where 1 =1 "
            Else
                SQL += " where 1<>1"
            End If
            SQL += "ORDER BY  A.YM" & vbCrLf
            DS = Exec(SQL, E_ExecType.DataSet)
            Me.DataGridView1.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView1, Me.ReturnCaption(2))
            Me.TabPage1date = String.Concat(" 按月統計  時間由：  ", startDate, "  到  ", endDate)

        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub SelectWithDate(ByVal B As Boolean)
        Try
            SQL = " SELECT A.FSALEDATE AS RIQI ,A.AMOUNT AS DANGTIAN , " & vbCrLf
            SQL += " ZENGZHANGLV=  CAST(((A.AMOUNT-ISNULL(B.AMOUNT,A.AMOUNT))/( Case when ISNULL(B.AMOUNT,A.AMOUNT)=0 then 1 else ISNULL(B.AMOUNT,A.AMOUNT) end ))*100 AS VARCHAR(100))+'%' ,B.AMOUNT AS QIANYITIAN " & vbCrLf
            SQL += " FROM " & vbCrLf
            SQL += " (SELECT  FSALEDATE,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT " & vbCrLf
            SQL += " FROM  SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += " GROUP BY FSALEDATE ) A LEFT JOIN" & vbCrLf
            SQL += " (SELECT  FSALEDATE,SUM(ISNULL(FSUMMONEY,'0.00')) AS AMOUNT " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO= B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker2.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += " GROUP BY FSALEDATE ) B" & vbCrLf
            SQL += " ON DATEADD(DAY,1,CONVERT(DATETIME,B.FSALEDATE))=CONVERT(DATETIME,A.FSALEDATE) "
            If B = True Then
                SQL += " where 1 =1 "
            Else
                SQL += " where 1<>1"
            End If
            SQL += " ORDER BY A.FSALEDATE " & vbCrLf
            DS = Exec(SQL, E_ExecType.DataSet)
            Me.DataGridView1.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView1, Me.ReturnCaption(1))
            Me.TabPage1date = String.Concat("【按天統計  時間由：", startDate, "  到  ", endDate, "】")


        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub Frm_SALRetailGrowth_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            SelectWithDate(False)
            AVGSalPrice(False)
            AVGSalPrice2(False)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint, DataGridView2.RowPostPaint, DataGridView3.RowPostPaint
        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DGV_Goods_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
        If Me.RBtnY.Checked = True Then
            Me.SetPrint(Me.DataGridView1, "SAL", "SaleCountByYear.rpt", "TextDateFromTo", Me.TabPage1date)
        End If
        If Me.RBtnM.Checked = True Then
            Me.SetPrint(Me.DataGridView1, "SAL", "SaleCountByMonth.rpt", "TextDateFromTo", Me.TabPage1date)
        End If
        If Me.RBtnD.Checked = True Then
            Me.SetPrint(Me.DataGridView1, "SAL", "SaleCountByDate.rpt", "TextDateFromTo", Me.TabPage1date)
        End If

    End Sub
    Private Sub BtnPrint1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint1.Click
        Me.SetPrint(Me.DataGridView2, "SAL", "AVGSalPrice.rpt", "TextDateFromTo", Me.TabPage2date)
    End Sub

#Region "SetPrint 用於給actionprint()方法提供打印設置，設置好報表的登錄信息、文件路徑以及要更改的TextDateFromTo（textobject對象）的值"
    ''' <summary>
    ''' 用於給actionprint()方法提供打印設置
    ''' </summary>
    ''' <param name="DataGV">需要打印的數據來源，顯示在那個DataGridView</param>
    ''' <param name="modelName">當前所在的模塊，通過這個可以定位到模塊所在的報表文件夾</param>
    ''' <param name="reportName">報表文件名</param>
    ''' <remarks></remarks>
    Private Sub SetPrint(ByVal DataGV As System.Windows.Forms.DataGridView, ByVal modelName As String, ByVal reportName As String, ByVal TextObjectName As String, ByVal TextObjectValue As String)
        Dim Frm As New Frm_Wating()
        Dim mDT As DataTable
        Try
            If (DataGV.RowCount <= 0) Then
                MsgBox("對不起，沒有數據可列印！", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Exit Sub
            End If
            '登錄等待窗體
            Frm.Show()
            '獲取和設置報表登錄信息和路徑
            Dim myReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim Pathstr As String = ""
            Pathstr = GetReportPath(modelName, reportName)
            myReportDoc.Load(Pathstr)
            ModSys.SetCrystalReportLoginfo(myReportDoc)

            '獲取報表數據源（將GridView的數據源轉化成DataTable，作為報表的數據源）
            mDT = CType(DataGV.DataSource, DataTable)
            myReportDoc.SetDataSource(mDT)
            With My.Forms.Frm_Report.CrystalReportViewer1
                .ReportSource = myReportDoc
                .Zoom(1)
                .DisplayGroupTree = False
            End With

            If Not TextObjectValue Is Nothing Then
                Me.setTextObject(myReportDoc, TextObjectName, TextObjectValue)
            End If
            Frm.Dispose()
            Frm_Report.ShowDialog()

        Catch ex As Exception
            MsgBox("對不起，打印出錯！" & ex.Message & ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        Finally
            mDT = Nothing
        End Try
    End Sub

#End Region

    Private Sub setTextObject(ByRef Report As ReportDocument, ByVal textObjectName As String, ByVal textObjectValue As String)
        Dim textobj As TextObject
        textobj = CType(Report.ReportDefinition.ReportObjects(textObjectName), TextObject)
        textobj.Text = textObjectValue
    End Sub

    Private Sub BtnJS3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnJS3.Click
        startDate = Me.DateTimePicker5.Text
        endDate = Me.DateTimePicker6.Text
        AVGSalPrice2(True)
    End Sub
    Private Sub AVGSalPrice2(ByVal B As Boolean)
        Try
            SQL = "   SELECT A.FSALEDATE, SUM(FSUMMONEY) AS TAMOUNT,C.AMOUNT,AVG= SUM(FSUMMONEY)/C.AMOUNT " & vbCrLf
            SQL += " FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B  " & vbCrLf
            SQL += " ON A.FSALEORDENO = B.FSALEORDENO LEFT JOIN  " & vbCrLf
            SQL += " ( SELECT  FSALEDATE,SUM(FSUMCOUNT)AS AMOUNT FROM SAL_SALEORDEA A LEFT JOIN SAL_SALEORDEB B ON A.FSALEORDENO = B.FSALEORDENO " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND FSALEDATE  BETWEEN '" & Me.DateTimePicker5.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker6.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            SQL += " GROUP BY FSALEDATE )C  ON A.FSALEDATE = C.FSALEDATE " & vbCrLf
            SQL += " WHERE FLAG <> 1 AND  FORDESTATUS IN ('A','B','C','F') AND  A.FSALEDATE  BETWEEN '" & Me.DateTimePicker5.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.DateTimePicker6.Value.ToString("yyyy-MM-dd") & "' " & vbCrLf
            If B = True Then
                SQL += " AND 1 = 1 "
            Else
                SQL += " AND 1<>1"
            End If
            SQL += "   GROUP BY A.FSALEDATE,C.AMOUNT order by a.FSALEDATE " & vbCrLf
            DS = Exec(SQL, E_ExecType.DataSet)
            Me.DataGridView3.DataSource = DS.Tables(0)
            BindDataGridViewCaption(Me.DataGridView3, Me.ReturnCaption(5))
            Me.TabPage3date = String.Concat("統計時間由：  ", startDate, "  到  ", endDate)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub BtnPrint3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint3.Click
        Me.SetPrint(Me.DataGridView3, "SAL", "AVGSalPrice1.rpt", "TextDateFromTo", Me.TabPage3date)
    End Sub
End Class
